package ie.wit.loanmanager.utils;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.rmi.CORBA.Util;

/**
* Static convenience methods for common web-related tasks.
*/
public final class Validate {
  

	/**
	 * Validate the form of an email address.
	 * @param email
	 * @return true if email is valid or false if not
	 */
	public static boolean isValidEmailAddress(String email) {
		   boolean result = true;
		   try {
		      InternetAddress emailAddr = new InternetAddress(email);
		      emailAddr.validate();
		   } catch (AddressException ex) {
		      result = false;
		   }
		   return result;
	}
	
	/**
	 * This method is used to validate a date
	 * @param date
	 * @return
	 */
	public static boolean isValidDate(String date) {
			try {
				int year = Integer.parseInt(date.split("-")[2]);
				int month = Integer.parseInt(date.split("-")[1]);
				int day = Integer.parseInt(date.split("-")[0]);	
			} catch (Exception e) {
				return false;
			}
		return true;
	}
  
}
 